package com.kgar.config;

import com.kgar.interceptor.CorsInterceptor;
import com.kgar.interceptor.LoginInterceptor;
import com.kgar.interceptor.RefreshTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Trimb
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/job",
                        "/job/tags",
                        "/job/hotTags",
                        "/job/getMarked",
                        "/login",
                        "/login/code",
                        "/upload/**",
                        "/search/**"
                ).order(2);
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).order(1);
        registry.addInterceptor(new CorsInterceptor()).order(0);
    }
}
